package com.qitmiaojie.service.impl;

import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qitmiaojie.controller.utils.Result;
import com.qitmiaojie.pojo.Role;
import com.qitmiaojie.pojo.Student;
import com.qitmiaojie.pojo.User;
import com.qitmiaojie.pojo.dto.UserTable;
import com.qitmiaojie.service.StudentService;
import com.qitmiaojie.mapper.StudentMapper;
import com.qitmiaojie.utils.BeanCopyUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student>
    implements StudentService{

    @Override
    public Result selectByPage(String name, Integer currentPage, Integer size) {
        IPage<Student> pages = new Page<>(currentPage,size);
        LambdaQueryWrapper<Student> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(!StringUtils.isEmpty(name),Student::getName,name);
        page(pages,queryWrapper);
        Result result=new Result();
        if (pages.getTotal() == 0){
            result.setObject(MapUtil.builder()
                    .put("TotalCount", 0)
                    .put("data", null)
                    .build());
            result.setMsg("无结果");
            result.setStateCode(50);
        }else {

            List<Student> studentList = pages.getRecords();
            result.setObject(MapUtil.builder()
                    .put("TotalCount", pages.getTotal())
                    .put("data", studentList)
                    .build());
            result.setMsg("查询成功");
            result.setStateCode(200);
        }
        return result;
    }
}




